package com.person.leetcode.editor.cn;

import java.util.HashMap;

/**
 * 12.整数转罗马数字
 * 2022-06-06 10:22:50
 **/
public class Sequence_0012_IntegerToRoman {
    public static void main(String[] args) {
        Solution solution = new Sequence_0012_IntegerToRoman().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        /**
         * I             1
         * IV            4
         * V             5
         * IX            9
         * X             10
         * XL            40
         * L             50
         * XC            90
         * C             100
         * CD            400
         * D             500
         * CM            900
         * M             1000
         *
         * @param num
         * @return
         */
        public String intToRoman(int num) {
            //0 ~ 3999
            HashMap<Integer, String> nuberMap = new HashMap<>();

            int thoNum = num / 1000;         //3  0 - 3
            int hunNum = num % 1000 / 100;   //9  0 - 9
            int tenNum = num % 100 / 10;      //9
            int oneNum = num % 10;           //9

            StringBuilder ans = new StringBuilder();

            //千位
            for (int i = 0; i < thoNum; i++) {
                ans.append("M");
            }
            //百位
            if (hunNum > 0 && hunNum < 4) {
                for (int i = 0; i < hunNum; i++) {
                    ans.append("C");
                }
            } else if (4 == hunNum) {
                ans.append("CD");
            } else if (5 <= hunNum && hunNum < 9) {
                ans.append("D");
                for (int i = 0; i < hunNum - 5; i++) {
                    ans.append("C");
                }
            } else if (9 == hunNum) {
                ans.append("CM");
            }
            //十位
            if (tenNum > 0 && tenNum < 4) {
                for (int i = 0; i < tenNum; i++) {
                    ans.append("X");
                }
            } else if (4 == tenNum) {
                ans.append("XL");
            } else if (5 <= tenNum && tenNum < 9) {
                ans.append("L");
                for (int i = 0; i < tenNum - 5; i++) {
                    ans.append("X");
                }
            } else if (9 == tenNum) {
                ans.append("XC");
            }
            //个位
            if (oneNum > 0 && oneNum < 4) {
                for (int i = 0; i < oneNum; i++) {
                    ans.append("I");
                }
            } else if (4 == oneNum) {
                ans.append("IV");
            } else if (5 <= oneNum && oneNum < 9) {
                ans.append("V");
                for (int i = 0; i < oneNum - 5; i++) {
                    ans.append("I");
                }
            } else if (9 == oneNum) {
                ans.append("IX");
            }

            return ans.toString();
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}